const events = require("events");
const EventEmitter = events.EventEmitter;
function Dog(dogName, energy) {
    this.dogName = dogName;
    this.energy = energy;
    EventEmitter.call(this);
    this.on("bark", () => {

        if (this.energy > -1) {
            console.log(this.dogName + " is barking,energy is" + this.energy);
        }
        else {
            process.exit();
            //退出来
        }
        this.energy--;
    })
}
Dog.prototype = EventEmitter.prototype;
//dog实例对象继承了EventEmitter的特性和方法
let dog = new Dog("taidi", 5);
let dog2 = new Dog("zangao", 7)
// dog.on("bark", () => {
//     console.log("taidi is barking");
// })
let intervalId = setInterval(() => {
    dog.emit("bark");
    dog2.emit("bark");
}, 1000)
// dog2.on("bark", () => {
//     console.log("zangao is barking")
// })
// dog2.emit("bark")
// console.log(dog);
